package net.zjitc.summary.user;

import java.util.Scanner;

/**
 * @Author admin
 * @Date 2019/4/16 14:13
 * 测试类（界面）
 */
public class UserTest {
    static Scanner scannerInt = new Scanner(System.in);
    static Scanner scannerString = new Scanner(System.in);
    /*创建工具类对象*/
    /*    static UserDao dao = new UserDaoSet();*/
    /* static UserDao dao = new UserDaoHashMap();*/
    static UserDao dao = new UserDaoIO();

    public static void main(String[] args) {
        while (true) {
            System.out.println("------欢迎光临------");
            System.out.println("1-注册");
            System.out.println("2-登陆");
            System.out.println("3-查询所有");
            System.out.println("4-删除");
            System.out.println("5-退出");
            System.out.println("请输入你的选择：");
            int choose = scannerInt.nextInt();
            switch (choose) {
                case 1:
                    registerUI();
                    break;
                case 2:
                    loginUI();
                    break;
                case 3:
                    selectUI();
                    break;
                case 4:
                    deleteUI();
                    break;
                case 5:
                    System.out.println("退出了");
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入有误！");
                    break;
            }
        }
    }


    private static void registerUI() {
        System.out.println("------注册界面------");
        System.out.println("请输入用户名：");
        String name = scannerString.nextLine();
        System.out.println("请输入密码：");
        String password = scannerString.nextLine();
        System.out.println("请输入email");
        String email = scannerString.nextLine();
        /*把用户输入的信息封装在一个用户对象中*/
        User user = new User(name, password, email);
        /*调用工具类的方法完成注册功能*/
        dao.register(user);
    }

    private static void loginUI() {
        System.out.println("------登陆界面------");
        System.out.println("请输入用户名：");
        String name = scannerString.nextLine();
        System.out.println("请输入密码：");
        String password = scannerString.nextLine();
        /*调用工具类的方法完成登陆功能*/
        User user = dao.login(name, password);
        if (user == null) {
            System.out.println("登陆失败！账号或密码错误");
        } else {
            System.out.println("登陆成功！欢迎" + user.getName());
        }
    }

    private static void selectUI() {
        System.out.println("------查询界面------");
        dao.selectAll();
    }

    private static void deleteUI() {
        System.out.println("------删除界面------");
        System.out.println("请输入您要删除的用户名");
        String name=scannerString.nextLine();
        dao.delete(name);
    }
}
